<template>
	<view>
		<u-navbar back-text="" :title="title"></u-navbar>
		<scroll-view class="main-content" @scrolltolower="loadMoreBook" scroll-y>
			<sl-filter :ref="'slFilter'" :isTransNav="false" themeColor="#92c8ff" :menuList="menuList"
			 @result="result" style="z-index: 100;"></sl-filter>
			<view class="book-list">
				<detailCard v-for="item in bookList" :key="item.id" :name="item.name" :writer="item.writer" :is_over="item.is_over"
				 :type="item.type" :intro="item.intro" :id="item.id" :image="item.image" />
				 <u-loadmore :status="status" margin-top="20" margin-bottom="20" />
			</view>
		</scroll-view>
	</view>
</template>

<script>
	import slFilter from '../../components/sl-filter/sl-filter';
	import DetailCard from '../../components/DetailCard'
	import {
		getSearchList
	} from '../../api/list.js'
	export default {
		components: {
			slFilter,
			DetailCard
		},
		data() {
			return {
				title: '所有小说',
				type: undefined,
				updateDay: undefined,
				isOver: undefined,
				orderBy:1,
				page: 1,
				lastPage:0,
				status: 'loadMore',
				menuList: [{
						'title': '排序',
						'key': 'orderBy',
						'isSort': true,
						'defaultSelectedIndex': 0,
						'detailList': [{
								'title': '正序',
								'value': 1
							},
							{
								'title': '倒序',
								'value': 2
							}
						]
					},
					{
						'title': '更新时间',
						'key': 'updateDay：',
						'isMutiple': false,
						'detailTitle': '',
						'defaultSelectedIndex': 0,
						'detailList': [{
								'title': '全部',
								'value': undefined
							},
							{
								'title': '三日内',
								'value': 3
							},
							{
								'title': '一周内',
								'value': 7
							},
							{
								'title': '半月内',
								'value': 15
							},
							{
								'title': '一月内',
								'value': 30
							}
						]
					},
					{
						'title': '更新进度',
						'key': 'isOver',
						'isMutiple': false,
						'detailTitle': '',
						'defaultSelectedIndex': 0,
						'detailList': [{
								'title': '全部',
								'value': undefined
							},
							{
								'title': '连载中',
								'value': 1
							},
							{
								'title': '已完本',
								'value': 2
							}
						]
					}
				],
				bookList: []
			}
		},
		onLoad(option) {
			if (option.title && option.type) {
				this.title = option.title;
				this.type = option.type;
			}
			this.getSearchList();
		},
		methods: {
			result(e) {
				this.updateDay = e.updateDay;
				this.isOver = e.isOver;
				this.orderBy = e.orderBy;
				this.page = 1;
				this.bookList = [];
				this.getSearchList();
			},
			getSearchList() {
				this.status = 'loading'
				if (this.page == this.lastPage) {
					this.status = 'nomore'
					return
				}
				getSearchList({
					type: this.type,
					updateDay: this.updateDay,
					isOver: this.isOver,
					page: this.page,
					orderBy:this.orderBy
				}).then(res => {
					this.bookList = this.bookList.concat(res.data.data);
					this.lastPage = res.data.last_page;
					this.page += 1;
				})
			},
			loadMoreBook:_.throttle(function(){this.getSearchList()},500)
		}
	}
</script>

<style scoped>
	.book-list{
		padding: 20rpx 40rpx 0 40rpx;
		z-index: 10;
		height:85vh;
	}
</style>
